<%@ page contentType="text/html;charset=UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext['request'].contextPath}" />
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>index</title>
<SCRIPT type="text/javascript" src="${ctx }/static/js/jquery-1.7.2.min.js"></SCRIPT>
<!-- bootstrap -->
<link rel="stylesheet" type="text/css" media="screen"
	href="${ctx }/static/bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css" media="screen"
	href="${ctx }/static/bootstrap/css/bootstrap-responsive.css">
<SCRIPT type="text/javascript">
function form_submit() {
	var system_website = $("input[name='system_website']").val();
	var system_name = $("input[name='system_name']").val();
	var system_icp = $("input[name='system_icp']").val();
	var email_authuser = $("input[name='email_authuser']").val();
	var email_authpassword = $("input[name='email_authpassword']").val();
	var email_smtphost = $("input[name='email_smtphost']").val();
	var email_smtpport = $("input[name='email_smtpport']").val();
	var taobao_appkey = $("input[name='taobao_appkey']").val();
	var taobao_appsecret = $("input[name='taobao_appsecret']").val();
	var taobao_session = $("input[name='taobao_session']").val();
	var taobao_submiturl = $("input[name='taobao_submiturl']").val();
	
	//TODO 验证
	
	var url = "${ctx }/admin/config/update";
	var params = {
		system_website:system_website,
		system_name:system_name,
		system_icp:system_icp,
		email_authuser:email_authuser,
		email_authpassword:email_authpassword,
		email_smtphost:email_smtphost,
		email_smtpport:email_smtpport,
		taobao_appkey:taobao_appkey,
		taobao_appsecret:taobao_appsecret,
		taobao_session:taobao_session,
		taobao_submiturl:taobao_submiturl
	};
	$.post(url, params, function(data) {
		if(data.state == 'ok') {
			alert("修改成功");
		} else {
			alert("修改失败");
		}
	}, 'json');
	
	
}
function alarm(name, msg) {
	var obj = $("#tr_" + name);
	var obj2 = $("#tr_"+name + " td").eq(2);
	var html = obj2.html();
	obj.addClass("control-group error");
	obj2.html("<font color='red'>"+msg+"</font>");
	setTimeout(function() {
		//还原
		obj.removeClass("control-group error");
		obj2.html(html);
	}, 3000);
}
</SCRIPT>
<STYLE type="text/css">
BODY{
	BACKGROUND: #EEF2FB;
}
</STYLE>
</head>
<body>
<form id="form" onsubmit="return false" class="span8">
	<table class="table table-bordered table-striped">
		<colgroup>
			<col class="span1">
			<col class="span4">
			<col class="span3">
		</colgroup>
		<tr>
			<th colspan="3">系统配置</th>
		</tr>
		<tr id="tr_system_name">
			<td>网站名称：</td>
			<td><input type="text" name="system_name" value="${settings.system_name}"/></td>
			<td>&nbsp;</td>
		</tr>
		<tr id="tr_system_website">
			<td>网站根目录：</td>
			<td><input type="text" name="system_website" value="${settings.system_website }"/></td>
			<td>http://www.tbk.com</td>
		</tr>
		<tr id="tr_system_icp">
			<td>网站备案：</td>
			<td><input type="text" name="system_icp" value="${settings.system_icp }"/></td>
			<td>&nbsp;</td>
		</tr>
		<tr><th colspan="3">淘宝客参数</th></tr>
		<tr id="tr_taobao_appkey">
			<td>APPKEY：</td>
			<td><input type="text" name="taobao_appkey" value="${settings.taobao_appkey }"/></td>
			<td>&nbsp;</td>
		</tr>
		<tr id="tr_taobao_appsecret">
			<td>SECRETKEY：</td>
			<td><input type="text" name="taobao_appsecret" value="${settings.taobao_appsecret }"/></td>
			<td>&nbsp;</td>
		</tr>
		<tr id="tr_taobao_session">
			<td>SESSION：</td>
			<td>
				<span class="input-append">
					<input type="text" name="taobao_session" disabled="disabled" value="${settings.taobao_session }"/>
					<button type="button" class="btn">重新获取</button>
				</span>
			</td>
			<td>重新获取session需要登录淘宝，获得的session有效期为1年</td>
		</tr>
		<tr id="tr_taobao_submiturl">
			<td>API访问地址：</td>
			<td><input type="text" name="taobao_submiturl" value="${settings.taobao_submiturl }"/></td>
			<td>&nbsp;</td>
		</tr>
		
		<tr><th colspan="3">邮箱设置</th></tr>
		<tr id="tr_email_smtphost">
			<td>主机地址：</td>
			<td><input type="text" name="email_smtphost" value="${settings.email_smtphost }"/></td>
			<td>&nbsp;</td>
		</tr>	
		<tr id="tr_email_smtpport">
			<td>端口：</td>
			<td><input type="text" name="email_smtpport" value="${settings.email_smtpport }"/></td>
			<td>一般默认是25</td>
		</tr>	
		<tr id="tr_email_authuser">
			<td>用户名：</td>
			<td><input type="text" name="email_authuser" value="${settings.email_authuser }"/></td>
			<td>邮箱的登录名</td>
		</tr>	
		<tr id="tr_email_authpassword">
			<td class="">密码：</td>
			<td><input type="text" name="email_authpassword" value="${settings.email_authpassword }"/></td>
			<td>邮箱密码</td>
		</tr>	
		<tr>
			<td>&nbsp;</td>
			<td colspan="2">
				<button class="btn btn-success" onclick="form_submit()">保存</button>
				<INPUT type="reset" value="重置" class="btn"/> 
			</td>
		</tr>
	</table>
</form>
</body>
</html>